package view

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import mvc.model.inventory.GoodsTypeWare

class GoodsTypeView : LinearLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    private val mTextGoodsType = TextView(context)
    private val mTextName = TextView(context)
    private val mTextPrice = TextView(context)

    init {
        val params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 50)
        layoutParams = params
        orientation = LinearLayout.HORIZONTAL

        val params2 = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT)
        params2.weight = 1f

        mTextGoodsType.textSize = 30f
        mTextGoodsType.setTextColor(Color.BLACK)
        mTextGoodsType.gravity = Gravity.CENTER

        mTextName.textSize = 30f
        mTextName.setTextColor(Color.BLACK)
        mTextName.gravity = Gravity.CENTER

        mTextPrice.textSize = 30f
        mTextPrice.setTextColor(Color.BLACK)
        mTextPrice.gravity = Gravity.CENTER

        addView(mTextGoodsType, params2)
        addView(mTextName, params2)
        addView(mTextPrice, params2)
    }

    fun setModel(model: GoodsTypeWare) {
        mTextGoodsType.text = model.cargo.name
        mTextName.text = model.name
        mTextPrice.text = model.price
    }

}